#include"Sort.h"
void swap(int* x, int* y)
{
	int t = *x;
	*x = *y;
	*y = t;
}
void BubbleSort(int* arr, int n)
{
	int exchange = 0;
	for (int i = 0; i < n - 1; i++)
	{
		for (int j = 0; j < n - 1 - i; j++)
		{
			if (arr[j] > arr[j + 1])
			{
				swap(&arr[j], &arr[j + 1]);
				exchange = 1;
			}
		}
		if (exchange == 0)
			break;
	}
	
}
int* _QuickSort(int* arr, int left, int right)
{
	int keyi = left;
	left++;
	while (left <= right)
	{
		while (left <= right && arr[right] > arr[keyi])
		{
			right--;
		} 
		while (left <= right && arr[left] < arr[keyi])
		{
			left++;
		}
		if (left <= right)
		{
			swap(&arr[left++], &arr[right--]);
		}
	}
	swap(&arr[keyi], &arr[right]);
	return right;
	
}
void QuickSort(int* arr, int left, int right)
{
	if (left >= right)
	{
		return ;
	}
	int keyi = _QuickSort(arr, left,right);
		QuickSort(arr, left, keyi - 1);
		QuickSort(arr, keyi + 1,right);
}